package leetcode.weekly.week290;

import leetcode.IDebug;

public class Solution2 implements IDebug {

	public int countLatticePoints(int[][] circles) {
		int U = Integer.MIN_VALUE, D = Integer.MAX_VALUE, L = Integer.MAX_VALUE, R = Integer.MIN_VALUE;
		for (int i = 0; i < circles.length; i++) {
			int[] c = circles[i];
			int x = c[0], y = c[1], r = c[2];
			int up = y + r, down = y - r, left = x - r, right = x + r;
			U = Math.max(U, up);
			R = Math.max(R, right);
			D = Math.min(D, down);
			L = Math.min(L, left);
		}
		int ans = 0;
		for (int i = L; i <= R; i++) {
			for (int j = D; j <= U; j++) {
				int x1 = i, y1 = j;
				for (int k = 0; k < circles.length; k++) {
					int[] c = circles[k];
					int x = c[0], y = c[1], r = c[2];
					int dis1 = Math.abs(x1 - x);
					int dis2 = Math.abs(y1 - y);
					if (dis1 * dis1 + dis2 * dis2 <= r * r) {
						ans += 1;
						break;
					}
				}
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
